package com.funsport.controller.mobile;

import com.funsport.common.Result;
import com.funsport.entity.Club;
import com.funsport.entity.Event;
import com.funsport.entity.User;
import com.funsport.security.SecurityUtils;
import com.funsport.service.IRecommendationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 移动端推荐Controller
 *
 * @author Fun-Sport Team
 */
@Slf4j
@Tag(name = "移动端推荐", description = "移动端推荐相关接口")
@RestController
@RequestMapping("/mobile/recommendation")
@RequiredArgsConstructor
public class MobileRecommendationController {

    private final IRecommendationService recommendationService;

    @Operation(summary = "获取推荐活动")
    @GetMapping("/events")
    public Result<List<Event>> getRecommendedEvents(@RequestParam(defaultValue = "10") Integer limit) {
        Long userId = SecurityUtils.getCurrentUserId();
        List<Event> events = recommendationService.recommendEventsForUser(userId, limit);
        return Result.success(events);
    }

    @Operation(summary = "获取推荐俱乐部")
    @GetMapping("/clubs")
    public Result<List<Club>> getRecommendedClubs(@RequestParam(defaultValue = "10") Integer limit) {
        Long userId = SecurityUtils.getCurrentUserId();
        List<Club> clubs = recommendationService.recommendClubsForUser(userId, limit);
        return Result.success(clubs);
    }

    @Operation(summary = "获取推荐用户")
    @GetMapping("/users")
    public Result<List<User>> getRecommendedUsers(@RequestParam(defaultValue = "10") Integer limit) {
        Long userId = SecurityUtils.getCurrentUserId();
        List<User> users = recommendationService.recommendUsersForUser(userId, limit);
        return Result.success(users);
    }

    @Operation(summary = "获取热门活动")
    @GetMapping("/hot-events")
    public Result<List<Map<String, Object>>> getHotEvents(
            @RequestParam(required = false) String city,
            @RequestParam(defaultValue = "7") Integer days,
            @RequestParam(defaultValue = "10") Integer limit) {
        List<Map<String, Object>> hotEvents = recommendationService.getHotEvents(city, days, limit);
        return Result.success(hotEvents);
    }

    @Operation(summary = "获取相似活动")
    @GetMapping("/similar-events/{eventId}")
    public Result<List<Event>> getSimilarEvents(
            @PathVariable Long eventId,
            @RequestParam(defaultValue = "5") Integer limit) {
        List<Event> similarEvents = recommendationService.getSimilarEvents(eventId, limit);
        return Result.success(similarEvents);
    }
}

